
#include "SteeringBehaviors.h"

/* Constructor
 */
SteeringBehaviors::SteeringBehaviors(IMovingObject* agent) :
		m_Vehicle(agent),
		m_SteeringForce(Ogre::Vector3::ZERO),
		m_Flags(0),
		m_DBoxLength(1.0),
		m_WeightCohesion(25.0),
		m_WeightAlignment(25.0),
		m_WeightSeperation(1000.0),
		m_WeightWander(10.0),
		m_WeightWallAvoid(100.0),
		m_ViewDistance(1000.0),
		m_Feelers(3),
		m_WallDetectionFeelerLength(500.0),
		m_Deceleration(NORMAL),
		m_TargetAgent1(NULL),
		m_TargetAgent2(NULL),
		m_Target(Ogre::Vector3::ZERO),
		m_WanderTarget(Ogre::Vector3::ZERO),
		m_WanderDistance(WANDER_DISTANCE),
		m_WanderJitter(WANDER_JITTER),
		m_WanderRadius(WANDER_RADIUS),
		m_WaypointSeekDistSq(WAYPOINT_SEEK_DISTANCE*WAYPOINT_SEEK_DISTANCE),
		m_WeightSeek(1.0),
		m_WeightFlee(1.0),
		m_WeightArrive(2.0),
		m_WeightPursuit(2.0),
		m_WeightOffsetPursuit(1.0),
		m_WeightInterpose(1.0),
		m_WeightHide(1.0),
		m_WeightEvade(1.0),
		m_WeightPathFollowing(1.0),
		m_WeightFlocking(1.0),
		m_CellSpaceOn(false),
		m_Offset(Ogre::Vector3::ZERO),
		m_SummingMethod(WEIGHTED_AVERAGE),
		PanicDistanceSq(50.0 * 50.0),
		ThreatRange(50.0)
{
	//Seed the random number generator
	//srand((unsigned)time(NULL));

	//Angle for the wander behavior
	double theta = std::rand() * (Ogre::Math::PI*2);

	//Set the wander target
	m_WanderTarget = Ogre::Vector3(m_WanderRadius * Ogre::Math::Sin(theta), m_WanderRadius * Ogre::Math::Cos(theta), 0);

	//Create a path for the path following behavior
	m_Path = new Path();
	m_Path->LoopOn();
	m_Path->AddWayPoint(Ogre::Vector3(150,150,0));
	m_Path->AddWayPoint(Ogre::Vector3(200,-150,0));
	m_Path->AddWayPoint(Ogre::Vector3(-300,300,0));
	m_Path->AddWayPoint(Ogre::Vector3(-1000,-1000,0));
	m_Path->AddWayPoint(Ogre::Vector3(-2500, -500, 0));
	m_Path->AddWayPoint(Ogre::Vector3(-1400, 250, 0));
	m_Path->AddWayPoint(Ogre::Vector3(-3000, 1500,0));
	m_Path->AddWayPoint(Ogre::Vector3(-4000, 3000, 0));
	m_Path->AddWayPoint(Ogre::Vector3(-2500, 3650,0));
	m_Path->AddWayPoint(Ogre::Vector3(-500, 2000,0));
	m_Path->AddWayPoint(Ogre::Vector3(0,500,0));
	m_Path->AddWayPoint(Ogre::Vector3(2500,1000,0));
}

/* Destructor
 */
SteeringBehaviors::~SteeringBehaviors()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::~SteeringBehaviors() ");
	}

	//Destroy the path
	delete m_Path;

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::~SteeringBehaviors() ");
	}
}

/* Calculate()
 * Tag other vehicles within sight of m_Vehicle and
 * calculate the steering force
 */
Ogre::Vector3 SteeringBehaviors::Calculate()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::Calculate() ");
	}

	//Reset the steering force
	m_SteeringForce = Ogre::Vector3::ZERO;

	if(!isSpacePartitioningOn())
	{
		if(On(seperation) || On(alignment) || On(cohesion))
		{
			Ogre::Vector3 to;
			double range;

			for(std::vector<IMovingObject*>::iterator it = GameServices::ObjectManager()->GetAutonomousList()->begin(); 
				it != GameServices::ObjectManager()->GetAutonomousList()->end();it++)
			{
				(*it)->UnTag();
				to = (*it)->GetPosition() - m_Vehicle->GetPosition();
				range = m_ViewDistance + (*it)->GetBRadius();

				if((*it) != m_Vehicle && to.length() < range*range)
				{
					(*it)->Tag();
				}
			}
		}
	}
	else
	{
		if(On(seperation) || On(alignment) || On(cohesion))
		{

		}
	}

	switch(m_SummingMethod)
	{
	case WEIGHTED_AVERAGE:
		m_SteeringForce = CalculateWeightedSum();
		break;
	case PRIORITIZED:
		m_SteeringForce = CalculatePrioritized();
		break;
	case DITHERED:
		m_SteeringForce = CalculateDithered();
		break;
	default:
		m_SteeringForce.ZERO;
		break;
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4&& 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::Calculate() ");
	}
	return m_SteeringForce;
}

/* ForwardComponent()
 * Return the dot product of m_Vehicles heading and the steering force applied
 */
double SteeringBehaviors::ForwardComponent()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::ForwardComponent() ");
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::ForwardComponent() ");
	}

	return m_Vehicle->GetHeading().dotProduct(m_SteeringForce);
}

/* SideComponent()
 * Return the dot product of m_Vehicles side component and the steering force applied
 */
double SteeringBehaviors::SideComponent()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::SideComponent() ");
	}


	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::SideComponent() ");
	}

	return m_Vehicle->GetPerp().dotProduct(m_SteeringForce);
}

/* SetTarget(Ogre::Vector3 Target)
 * Set Ogre::Vector3 m_Target equal to Target
 */
void SteeringBehaviors::SetTarget(Ogre::Vector3 Target)
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::SetTarget(Ogre::Vector3 Target) ");
	}

	if(GameServices::GameEngine()->GetLoggingLevel() == 5 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("New Target " + 
			Ogre::StringConverter::toString(Target));
	}

	m_Target = Target;

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::SetTarget(Ogre::Vector3 Target) ");
	}
}

/* SetTargetAgent1(IMovingObject* agent)
 * Set IMovingObject* m_TargetAgent1 = agent
 */
void SteeringBehaviors::SetTargetAgent1(IMovingObject* agent)
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::SetTargetAgent1(IMovingObject* agent) ");
	}

	if(GameServices::GameEngine()->GetLoggingLevel() == 5 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("Target Agent1 Position " +
			Ogre::StringConverter::toString(agent->GetPosition()));
	}

	m_TargetAgent1 = agent;

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::SetTargetAgent1(IMovingObject* agent) ");
	}
}

/* SetTargetAgent2(IMovingObject* agent)
 * Set IMovingObject* m_TargetAgent2 = agent;
 */
void SteeringBehaviors::SetTargetAgent2(IMovingObject* agent)
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::SetTargetAgent2(IMovingObject* agent) ");
	}

	if(GameServices::GameEngine()->GetLoggingLevel() == 5 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("Target Agent2 Position " +
			Ogre::StringConverter::toString(agent->GetPosition()));
	}

	m_TargetAgent2 = agent;

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::SetTargetAgent2(IMovingObject* agent) ");
	}
}

/* SetOffset(Ogre::Vector3 offset)
 * Set Ogre::Vector3 m_Offset = offset
 */
void SteeringBehaviors::SetOffset(Ogre::Vector3 offset)
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::SetOffset(Ogre::Vector3 offset) ");
	}

	if(GameServices::GameEngine()->GetLoggingLevel() == 5)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("New Offset " +
			Ogre::StringConverter::toString(offset));
	}

	m_Offset = offset;

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::SetOffset(Ogre::Vector3 offset) ");
	}
}
 
/* GetOffset()
 * Return Ogre::Vector3 m_Offset
 */
Ogre::Vector3 SteeringBehaviors::GetOffset()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::GetOffset()() ");
	}

	if(GameServices::GameEngine()->GetLoggingLevel() == 5 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("Current Offset " +
			Ogre::StringConverter::toString(m_Offset));
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::GetOffset()() ");
	}
	return m_Offset;
}
 
/* SetPath(std::list<Ogre::Vector3> newPath)
 * TODO
 */
void SteeringBehaviors::SetPath(std::list<Ogre::Vector3> newPath)
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::SetPath(std::list<Ogre::Vector3> newPath) ");
	}

	//m_Path->Set(newPath);

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::SetPath(std::list<Ogre::Vector3> newPath) ");
	}
}

/* CreateRandomPath(int numOfWaypoints, int mx, int my, int cx, int cy)
 * TODO
 */
void SteeringBehaviors::CreateRandomPath(int numOfWaypoints, int mx, int my, int cx, int cy)
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::CreateRandomPath(int numOfWaypoints, int mx, int my, int cx, int cy) ");
	}

	//m_Path->CreateRandomPath(numOfWaypoints, mx, my, cx, cy);

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::CreateRandomPath(int numOfWaypoints, int mx, int my, int cx, int cy) ");
	}
}

/* Force()
 * Return Ogre::Vector3 m_SteeringForce
 */
Ogre::Vector3 SteeringBehaviors::Force()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::Force() ");
	}

	if(GameServices::GameEngine()->GetLoggingLevel() == 5 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("Sum of all steering forces is " +
			Ogre::StringConverter::toString(m_SteeringForce));
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::Force() ");
	}
	return m_SteeringForce;
}

/* ToggleSpacePartitioning()
 * m_CellSpaceOn = !m_CellSpaceOn
 */
void SteeringBehaviors::ToggleSpacePartitioning()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::ToggleSpacePartitioning() ");
	}

	if(GameServices::GameEngine()->GetLoggingLevel() == 5)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("Space Partioning is set to " +
			Ogre::StringConverter::toString(m_CellSpaceOn, true));
	}

	m_CellSpaceOn = !m_CellSpaceOn;

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::ToggleSpacePartitioning() ");
	}
}

/* isSpacePartitioningOn()
 * Return m_CellSpaceOn
 */
bool SteeringBehaviors::isSpacePartitioningOn()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::isSpacePartitioningOn() ");
	}

	if(GameServices::GameEngine()->GetLoggingLevel() == 5)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage(Ogre::StringConverter::toString(m_CellSpaceOn, true));
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::isSpacePartitioningOn() ");
	}
	return m_CellSpaceOn;
}

/* SetSummingMethod(SummingMethod sm)
 * Set m_SummingMethod = sm
 */
void SteeringBehaviors::SetSummingMethod(SummingMethod sm)
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::SetSummingMethod(SummingMethod sm) ");
	}

	if(GameServices::GameEngine()->GetLoggingLevel() == 5)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("New Summing Method " +
			Ogre::StringConverter::toString(sm));
	}

	m_SummingMethod = sm;

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::SetSummingMethod(SummingMethod sm) ");
	}
}

/* SeekOn(IMovingObject* agent)
 * Set m_Flag |= seek
 */
void SteeringBehaviors::SeekOn(IMovingObject* agent)
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::SeekOn(IMovingObject* agent) ");
	}

	m_Flags |= seek;
	m_TargetAgent1 = agent;

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::SeekOn(IMovingObject* agent) ");
	}
}

/* PursuitOn(IMovingObject* agent)
 * Set m_Flags |= pursuit and m_TargetAgent1 = agent
 */
void SteeringBehaviors::PursuitOn(IMovingObject* agent)
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::PursuitOn(IMovingObject* agent) ");
	}

	m_Flags |= pursuit;

	m_TargetAgent1 = agent;

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::PursuitOn(IMovingObject* agent) ");
	}
}

/* ArriveOn(IMovingObject* agent)
 * Set m_Flags |= arrive
 */
void SteeringBehaviors::ArriveOn(IMovingObject* agent)
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::ArriveOn(IMovingObject* agent) ");
	}

	m_Flags |= arrive;
	m_TargetAgent1 = agent;

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::ArriveOn(IMovingObject* agent) ");
	}
}

/* InterposeOn(IMovingObject* agent1, IMovingObject* agent2)
 * Set m_Flags |= interpose and m_TargetAgent1 = agent1 and m_TargetAgent2 = agent2
 */
void SteeringBehaviors::InterposeOn(IMovingObject* agent1, IMovingObject* agent2)
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::InterposeOn(IMovingObject* agent1, IMovingObject* agent2) ");
	}

	m_Flags |= interpose;
	m_TargetAgent1 = agent1;
	m_TargetAgent2 = agent2;

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::InterposeOn(IMovingObject* agent1, IMovingObject* agent2) ");
	}
}

/* OffsetPursuitOn(IMovingObject* agent1, Ogre::Vector3 offset)
 * Set m_Flags |= offset and set m_TargetAgent1 = agent and set m_Offset = newoffset
 */
void SteeringBehaviors::OffsetPursuitOn(IMovingObject* agent, Ogre::Vector3 newoffset)
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::OffsetPursuitOn(IMovingObject* agent1, Ogre::Vector3 offset) ");
	}

	m_Flags |= offset_pursuit;
	m_TargetAgent1 = agent;
	m_Offset = newoffset;

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::OffsetPursuitOn(IMovingObject* agent1, Ogre::Vector3 offset) ");
	}
}

/* FleeOn(IMovingObject* agent)
 * Set m_Flags |= flee
 */
void SteeringBehaviors::FleeOn(IMovingObject* agent)
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::FleeOn(IMovingObject* agent) ");
	}

	m_Flags |= flee;
	m_TargetAgent1 = agent;

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::FleeOn(IMovingObject* agent) ");
	}
}

/* EvadeOn(IMovingObject* agent1)
 * 
 */
void SteeringBehaviors::EvadeOn(IMovingObject* agent)
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::EvadeOn(IMovingObject* agent1) ");
	}

	m_Flags |= evade;
	m_TargetAgent1 = agent;

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::EvadeOn(IMovingObject* agent1) ");
	}
}

/* HideOn(IMovingObject* agent1)
 * Set m_Flags |= hide and m_TargetAgent1 = agent
 */
void SteeringBehaviors::HideOn(IMovingObject* agent)
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::HideOn(IMovingObject* agent1) ");
	}

	m_Flags |= hide;
	m_TargetAgent1 = agent;

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::HideOn(IMovingObject* agent1) ");
	}
}

/* WallAvoidanceOn()
 * Set m_Flags |= wall_avoid
 */
void SteeringBehaviors::WallAvoidanceOn()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::WallAvoidanceOn() ");
	}

	m_Flags |= wall_avoid;

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::WallAvoidanceOn() ");
	}
}

/* PathFollowingOn()
 * Set m_Flags |= path_following
 */
void SteeringBehaviors::PathFollowingOn()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::PathFollowingOn() ");
	}

	m_Flags |= path_following;

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::PathFollowingOn() ");
	}
}

/* WanderOn()
 * Set m_Flags |= wander
 */
void SteeringBehaviors::WanderOn()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::WanderOn() ");
	}

	m_Flags |= wander;

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::WanderOn() ");
	}
}

/* SeperationOn()
 * m_Flags |= seperation
 */
void SteeringBehaviors::SeperationOn()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::SeperationOn() ");
	}

	m_Flags |= seperation;

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::SeperationOn() ");
	}
}

/* AlignmentOn()
 * m_Flags |= alignment
 */
void SteeringBehaviors::AlignmentOn()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::AlignmentOn() ");
	}

	m_Flags |= alignment;

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::AlignmentOn() ");
	}
}

/* CohesionOn()
 * m_Flags |= cohesion
 */
void SteeringBehaviors::CohesionOn()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::CohesionOn() ");
	}

	m_Flags |= cohesion;

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::CohesionOn() ");
	}
}

/* FlockingOn()
 * Turn Cohesion, Alignment, Seperation and Wander on
 */
void SteeringBehaviors::FlockingOn()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::FlockingOn() ");
	}

	CohesionOn();
	AlignmentOn();
	SeperationOn();
	WanderOn();

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::FlockingOn() ");
	}
}

/* SeekOff()
 * m_Flags ^= seek
 */
void SteeringBehaviors::SeekOff()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::SeekOff() ");
	}

	if(On(seek))
	{
		m_Flags ^= seek;
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::SeekOff() ");
	}
}

/* PursuitOff()
 * m_Flags ^= pursuit
 */
void SteeringBehaviors::PursuitOff()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::PursuitOff() ");
	}

	if(On(pursuit))
	{
		m_Flags ^= pursuit;
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::PursuitOff() ");
	}
}

/* ArriveOff()
 * m_Flags ^= arrive
 */
void SteeringBehaviors::ArriveOff()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::ArriveOff() ");
	}

	if(On(arrive))
	{
		m_Flags ^= arrive;
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::ArriveOff() ");
	}
}

/* InterposeOff()
 * m_Flags ^= interpose
 */
void SteeringBehaviors::InterposeOff()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::InterposeOff() ");
	}

	if(On(interpose))
	{
		m_Flags ^= interpose;
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::InterposeOff() ");
	}
}

/* OffsetPursuitOff()
 * m_Flags ^= offset_pursuit
 */
void SteeringBehaviors::OffsetPursuitOff()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::OffsetPursuitOff() ");
	}

	if(On(offset_pursuit))
	{
		m_Flags ^= offset_pursuit;
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::OffsetPursuitOff() ");
	}
}

/* FleeOff()
 * m_Flags ^= flee
 */
void SteeringBehaviors::FleeOff()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::FleeOff() ");
	}

	if(On(flee))
	{
		m_Flags ^= flee;
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::FleeOff() ");
	}
}

/* EvadeOff()
 * m_Flags ^= evade
 */
void SteeringBehaviors::EvadeOff()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::EvadeOff() ");
	}

	if(On(evade))
	{
		m_Flags ^= evade;
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::EvadeOff() ");
	}
}

/* HideOff()
 * m_Flags ^= hide
 */
void SteeringBehaviors::HideOff()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::HideOff() ");
	}

	if(On(hide))
	{
		m_Flags ^= hide;
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::HideOff() ");
	}
}

/* WallAvoidanceOff()
 * m_Flags ^= wall_avoid
 */
void SteeringBehaviors::WallAvoidanceOff()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::WallAvoidanceOff() ");
	}

	if(On(wall_avoid))
	{
		m_Flags ^= wall_avoid;
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::WallAvoidanceOff() ");
	}
}

/* PathFollowingOff()
 * m_Flags ^= path_following
 */
void SteeringBehaviors::PathFollowingOff()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::PathFollowingOff() ");
	}

	if(On(path_following))
	{
		m_Flags ^= path_following;
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::PathFollowingOff() ");
	}
}

/* WanderOff()
 * m_Flags ^= wander
 */
void SteeringBehaviors::WanderOff()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::WanderOff() ");
	}

	if(On(wander))
	{
		m_Flags ^= wander;
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::WanderOff() ");
	}
}

/* SeperationOff()
 * m_Flags ^= seperation
 */
void SteeringBehaviors::SeperationOff()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::SeperationOff() ");
	}

	if(On(seperation))
	{
		m_Flags ^= seperation;
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::SeperationOff() ");
	}
}

/* AlignmentOff()
 * m_Flags ^= alignment
 */
void SteeringBehaviors::AlignmentOff()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::AlignmentOff() ");
	}

	if(On(alignment))
	{
		m_Flags ^= alignment;
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::AlignmentOff() ");
	}
}

/* CohesionOff()
 * m_Flags ^= cohesion
 */
void SteeringBehaviors::CohesionOff()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::CohesionOff() ");
	}

	if(On(cohesion))
	{
		m_Flags ^= cohesion;
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::CohesionOff() ");
	}
}

/* FlockingOff()
 * Turn off Cohesion, Alignment, Seperaion and Wander
 */
void SteeringBehaviors::FlockingOff()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::FlockingOff() ");
	}

	CohesionOff();
	AlignmentOff();
	SeperationOff();
	WanderOff();

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::FlockingOff() ");
	}
}

/* isSeekOn()
 * Return On(seek)
 */
bool SteeringBehaviors::isSeekOn()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::isSeekOn() ");
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::isSeekOn() ");
	}
	return On(seek);
}

/* isPursuitOn()
 * Return On(pursuit)
 */
bool SteeringBehaviors::isPursuitOn()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::isPursuitOn() ");
	}


	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::isPursuitOn() ");
	}

	return On(pursuit);
}

/* isArriveOn()
 * Return On(arrive)
 */
bool SteeringBehaviors::isArriveOn()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::isArriveOn() ");
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::isArriveOn() ");
	}

	return On(arrive);
}

/* isInterposeOn()
 * Return On(interpose)
 */
bool SteeringBehaviors::isInterposeOn()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::isInterposeOn() ");
	}


	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::isInterposeOn() ");
	}

	return On(interpose);
}

/* isOffsetPursuitOn()
 * Return On(offset_pursuit)
 */
bool SteeringBehaviors::isOffsetPursuitOn()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::isOffsetPursuitOn() ");
	}


	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::isOffsetPursuitOn() ");
	}

	return On(offset_pursuit);
}

/* isFleeOn()
 * Return On(flee)
 */
bool SteeringBehaviors::isFleeOn()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::isFleeOn() ");
	}


	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::isFleeOn() ");
	}

	return On(flee);
}

/* isEvadeOn()
 * Return On(evade)
 */
bool SteeringBehaviors::isEvadeOn()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::isEvadeOn() ");
	}


	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::isEvadeOn() ");
	}

	return On(evade);
}

/* isHideOn()
 * Return On(hide)
 */
bool SteeringBehaviors::isHideOn()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::isHideOn() ");
	}


	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::isHideOn() ");
	}

	return On(hide);
}

/* isWallAvoidanceOn()
 * Return On(wall_avoid)
 */
bool SteeringBehaviors::isWallAvoidanceOn()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::isWallAvoidanceOn() ");
	}


	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::isWallAvoidanceOn() ");
	}

	return On(wall_avoid);
}

/* isPathFollowingOn()
 * Return On(path_following)
 */
bool SteeringBehaviors::isPathFollowingOn()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::isPathFollowingOn() ");
	}


	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::isPathFollowingOn() ");
	}

	return On(path_following);
}
 
/* isWanderOn()
 * Return On(wander)
 */
bool SteeringBehaviors::isWanderOn()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::isWanderOn() ");
	}


	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::isWanderOn() ");
	}

	return On(wander);
}

/* isSeperationOn()
 * Return On(seperation)
 */
bool SteeringBehaviors::isSeperationOn()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::isSeperationOn() ");
	}


	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::isSeperationOn() ");
	}

	return On(seperation);
}

/* isAlignmentOn()
 * Return On(alignment)
 */
bool SteeringBehaviors::isAlignmentOn()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::isAlignmentOn() ");
	}


	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::isAlignmentOn() ");
	}

	return On(alignment);
}

/* isCohesionOn()
 * Return On(cohesion)
 */
bool SteeringBehaviors::isCohesionOn()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::isCohesionOn() ");
	}


	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::isCohesionOn() ");
	}

	return On(cohesion);
}

/* isFlockingOn()
 * Return On(seperation) && On(alignment) && On(cohesion) && On(wander)
 */
bool SteeringBehaviors::isFlockingOn()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::isFlockingOn() ");
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::isFlockingOn() ");
	}

	return (On(seperation) && On(alignment) && On(cohesion) && On(wander));
}

/* GetDBoxLength()
 * Return double m_DboxLength
 */
double SteeringBehaviors::GetDBoxLength()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::GetDBoxLength() ");
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::GetDBoxLength() ");
	}

	return m_DBoxLength;
}

/* GetFeelers()
 * Return the std vector container m_Feelers
 */
std::vector<Ogre::Vector3> SteeringBehaviors::GetFeelers()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::GetFeelers() ");
	}


	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::GetFeelers() ");
	}

	return m_Feelers;
}

/* GetWanderJitter()
 * Retrun the double m_WanderJitter
 */
double SteeringBehaviors::GetWanderJitter()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::GetWanderJitter() ");
	}


	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::GetWanderJitter() ");
	}

	return m_WanderJitter;
}

/* GetWanderDistance()
 * m_WanderDistance
 */
double SteeringBehaviors::GetWanderDistance()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::GetWanderDistance() ");
	}


	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::GetWanderDistance() ");
	}

	return m_WanderDistance;
}

/* GetWanderRadius()
 * m_WanderRadius
 */
double SteeringBehaviors::GetWanderRadius()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::GetWanderRadius() ");
	}


	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::GetWanderRadius() ");
	}

	return m_WanderRadius;
}

/* GetSeperationWeight()
 * Return m_WeightSeperation
 */
double SteeringBehaviors::GetSeperationWeight()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::GetSeperationWeight() ");
	}


	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::GetSeperationWeight() ");
	}

	return m_WeightSeperation;
}

/* GetAlignmentWeight()
 * Return m_WeightAlignment
 */
double SteeringBehaviors::GetAlignmentWeight()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::GetAlignmentWeight() ");
	}


	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::GetAlignmentWeight() ");
	}

	return m_WeightAlignment;
}

/* GetCohesionWeight()
 * Return m_WeightCohesion
 */
double SteeringBehaviors::GetCohesionWeight()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::GetCohesionWeight() ");
	}


	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::GetCohesionWeight() ");
	}

	return m_WeightCohesion;
}

/* On(BehaviorType bt)
 * Returns true if (m_Flags & bt) == bt
 */
bool SteeringBehaviors::On(BehaviorType bt)
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::On(BehaviorType bt) ");
	}

	if(GameServices::GameEngine()->GetLoggingLevel() == 5 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("Is " + Ogre::StringConverter::toString(bt) + "on? " +
			Ogre::StringConverter::toString((m_Flags & bt) == bt, true));
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::On(BehaviorType bt) ");
	}

	return (m_Flags & bt) == bt;
}

/* AccumulateForce(Ogre::Vector3 &force, Ogre::Vector3 forceToAdd)
 *
 */
bool SteeringBehaviors::AccumulateForce(Ogre::Vector3 &RunningTotal, Ogre::Vector3 forceToAdd)
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::AccumulateForce(Ogre::Vector3 &force, Ogre::Vector3 forceToAdd)");
	}

	//if the Magnitude remaining before force is maxed out
	if(m_Vehicle->GetMaxForce() - (double)RunningTotal.length() <= 0.0) 
		return false;

	//if the Length of the force to add < Magnitude remaining before force is maxed out
	if((double)forceToAdd.length() < m_Vehicle->GetMaxForce() - (double)RunningTotal.length())
	{
		//then add the force to the running total
		RunningTotal += forceToAdd;
	}
	else
	{
		//else normalise the force to add and multiply it by the Magnitude remaining before force is maxed out
		RunningTotal += forceToAdd.normalise() * (m_Vehicle->GetMaxForce() - (double)RunningTotal.length()) ;
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::AccumulateForce(Ogre::Vector3 &force, Ogre::Vector3 forceToAdd) ");
	}
}

/* CreateFeelers()
 * Fill the std vector m+Feelers with three vectors
 * [0] dircetly infront of the agent
 * [1] to the right 45 degrees
 * [2] to the left 45 degrees
 */
void SteeringBehaviors::CreateFeelers()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::CreateFeelers() ");
	}

	//First Feeler is stright ahead
	m_Feelers[0] = m_Vehicle->GetPosition() + m_Vehicle->GetHeading() * m_WallDetectionFeelerLength; 

	//Second Feeler is half way between the heading and the perpendicular and half the size of the forward feeler
	m_Feelers[1] =  m_Vehicle->GetPosition() + (m_WallDetectionFeelerLength/2) * (m_Vehicle->GetHeading() + m_Vehicle->GetPerp());

	//The Third Feeler is half way between the heading and the reflection on the perpendicular and half the size of the forward feeler
	m_Feelers[2] = m_Vehicle->GetPosition() + (m_WallDetectionFeelerLength/2) * (m_Vehicle->GetHeading() + m_Vehicle->GetPerp().reflect(m_Vehicle->GetPerp()));

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::CreateFeelers() ");
	}
}


/* BEGIN BEHAVIOR IMPLEMENTATIONS */


/* Seek(Ogre::Vector3 TargetPos)
 *
 */
Ogre::Vector3 SteeringBehaviors::Seek(Ogre::Vector3 TargetPos)
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::Seek(Ogre::Vector3 TargetPos) ");
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::Seek(Ogre::Vector3 TargetPos) ");
	}
	
	Ogre::Vector3 ToPosition = TargetPos - m_Vehicle->GetPosition();
	ToPosition.normalise();
	Ogre::Vector3 DesiredVelocity = ToPosition * m_Vehicle->GetMaxSpeed();
	return DesiredVelocity - m_Vehicle->GetVelocity();
}

/* Pursuit( IMovingObject* agent)
 *
 */
Ogre::Vector3 SteeringBehaviors::Pursuit(IMovingObject* agent)
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::Pursuit( IMovingObject* agent) ");
	}

	//Calculate how far the evader is from the owning agent
	Ogre::Vector3 ToEvader = agent->GetPosition() - m_Vehicle->GetPosition();

	double RelativeHeading = m_Vehicle->GetHeading().dotProduct(agent->GetHeading());

	//If the evader is infront of us just seek its position
	if(ToEvader.dotProduct(m_Vehicle->GetHeading()) > 0 && (RelativeHeading < -.95))
	{
		if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
		{
			Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::Pursuit( IMovingObject* agent) ");
		}
		return Seek(agent->GetPosition());
	}

	//Else attempt to predict where the evader will be in to future and seek that position
	double LookAheadTime = (double)ToEvader.length() / (m_Vehicle->GetMaxSpeed() + agent->Speed());

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::Pursuit( IMovingObject* agent) ");
	}

	return Seek(agent->GetPosition() + agent->GetVelocity() * LookAheadTime);
}

/* Arrive(Ogre::Vector3 TargetPos, Deceleration decel)
 *
 */
Ogre::Vector3 SteeringBehaviors::Arrive(Ogre::Vector3 TargetPos, Deceleration decel)
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::Arrive(Ogre::Vector3 TargetPos, Deceleration decel) ");
	}

	//Calculate how far the owning agent is from the target position
	Ogre::Vector3 ToTarget = TargetPos - m_Vehicle->GetPosition();

	double distance = ToTarget.length();

	if(distance > 0)
	{
		//A small double to adjust the Deceleration integer enum
		const double Tweaker = 0.3;

		//The speed required to reach the target with selected deceleration
		double speed = distance / ((double)decel * Tweaker);

		//Make sure the speed does not exceed the maximum allowed for the vehicle
		speed = std::min(speed, m_Vehicle->GetMaxSpeed());

		//Calculate the desired velocity
		Ogre::Vector3 DesiredVelocity = ToTarget * speed / distance;

		if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
		{
			Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::SteeringBehaviors() ");
		}

		return (DesiredVelocity - m_Vehicle->GetVelocity());
	}


	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::SteeringBehaviors() ");
	}

	return Ogre::Vector3::ZERO;
}

/* Interpose(IMovingObject* agentA,  IMovingObject* agentB)
 *
 */
Ogre::Vector3 SteeringBehaviors::Interpose(IMovingObject* agentA,  IMovingObject* agentB)
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::Interpose( IMovingObject* agentA,  IMovingObject* agentB) ");
	}

	//Calculate the midpoint between the two given agents
	Ogre::Vector3 MidPoint = ((agentA->GetPosition() + agentB->GetPosition()) / 2.0);

	//Calculate how long it will take to reach the midpoint at maximum speeds
	double TimeToReachMidPoint = m_Vehicle->GetPosition().distance(MidPoint) / m_Vehicle->GetMaxSpeed();

	//Assume A & B stay on current path and calculate their future positions
	Ogre::Vector3 PosA = agentA->GetPosition() + agentA->GetVelocity() * TimeToReachMidPoint;
	Ogre::Vector3 PosB = agentB->GetPosition() + agentB->GetVelocity() * TimeToReachMidPoint;

	//Recalculate the midpoint for these future positions
	MidPoint = (PosA + PosB) / 2.0;

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::Interpose( IMovingObject* agentA,  IMovingObject* agentB) ");
	}

	//Seek or Arrive to the calculated point
	return Arrive(MidPoint, FAST);
}

/* OffsetPursuit(IMovingObject* agent, Ogre::Vector3 offset)
 *
 */
Ogre::Vector3 SteeringBehaviors::OffsetPursuit(IMovingObject* agent, Ogre::Vector3 offset)
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::OffsetPursuit( IMovingObject* agent, Ogre::Vector3 offset) ");
	}

	Ogre::Radian theta;		//Create a variable for the angle between the world x-axis and the players local x-axis

	if(agent->GetPerp() == Ogre::Vector3::ZERO)
	//If the local perpenducular is zero or aligned to the world x set theta to zero
	{
		theta = Ogre::Radian(Ogre::Degree(0));
	}
	else
	//else calculate the angle between the local perpendicular the the world x-axis
	{
		theta = agent->GetPerp().angleBetween(Ogre::Vector3::UNIT_X);
	}

	if(agent->GetHeading().x > 0)
	//The angleBetween function only gives positive results change to negative rotation if the heading is positive
	{
		theta = -theta;
	}


	if(theta != Ogre::Radian(Ogre::Degree(0)))
	//If theta doesn't equal zero rotate the offset
	{
		offset = Ogre::Matrix3( Ogre::Math::Cos(theta), -Ogre::Math::Sin(theta), 0,
								Ogre::Math::Sin(theta), Ogre::Math::Cos(theta), 0,
								0,0,1 ) * offset;
	}

	//Translate the local coords calculated to world coords
	Ogre::Vector3 WorldOffset = GameServices::OgreManager()->GetSceneManager()->getSceneNode(agent->GetName())->convertLocalToWorldPosition(offset);

	//Calculate the distance the owning vehicle has to travel to get to the offset
	Ogre::Vector3 ToOffset = WorldOffset - m_Vehicle->GetPosition();

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("Local OffSet : " + Ogre::StringConverter::toString(offset));
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("World OffSet : " + Ogre::StringConverter::toString(WorldOffset));
	}

	//Calculate the look ahead time
	double LookAheadTime = (double)ToOffset.length() / (m_Vehicle->GetMaxSpeed() + agent->Speed());

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::OffsetPursuit( IMovingObject* agent, Ogre::Vector3 offset) ");
	}

	//Call arrive with the position
	return Arrive(WorldOffset + agent->GetVelocity() * LookAheadTime, FAST);
}

/* Flee(Ogre::Vector3 hunterPos)  
 *
 */
Ogre::Vector3 SteeringBehaviors::Flee(Ogre::Vector3 hunterPos)  
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::Flee(Ogre::Vector3 hunterPos)   ");
	}

	//Only run if the hunter is within a certain range
	if(m_Vehicle->GetPosition().distance(hunterPos) > PanicDistanceSq)
	{
		Ogre::Real test = m_Vehicle->GetPosition().distance(hunterPos);
		if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
		{
			Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::Flee(Ogre::Vector3 hunterPos)   ");
		}

		return Ogre::Vector3::ZERO;
	}

	Ogre::Vector3 ToPosition = m_Vehicle->GetPosition() - hunterPos;
	ToPosition.normalise();
	Ogre::Vector3 DesiredVelocity =  ToPosition * m_Vehicle->GetMaxSpeed();

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::Flee(Ogre::Vector3 hunterPos)   ");
	}

	return (DesiredVelocity - m_Vehicle->GetVelocity());
}

/* Evade(IMovingObject* chaser)
 * Flee from the chasers predicted position
 */
Ogre::Vector3 SteeringBehaviors::Evade(IMovingObject* chaser)
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::Evade(IMovingObject* chaser) ");
	}

	//Get the vector from the owning agent to the chaser
	Ogre::Vector3 ToChaser = chaser->GetPosition() - m_Vehicle->GetPosition();

	//If the chaser is not in the ThreatRange squared do not move
	if(ToChaser.length()  > ThreatRange * ThreatRange)
	{
		if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
		{
			Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::Evade(IMovingObject* chaser) ");
		}
		return Ogre::Vector3::ZERO;
	}

	//Else calculate the look ahead time and flee from the chasers predicted position
	double LookAheadTime = ToChaser.length() / (m_Vehicle->GetMaxSpeed() + chaser->Speed());

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::Evade(IMovingObject* chaser) ");
	}

	return Flee(chaser->GetPosition() + chaser->GetVelocity() * LookAheadTime);
}

/* Hide( IMovingObject* hunter)
 * Find the best hiding spot given a vector of stationary objects and a hunter
 */
Ogre::Vector3 SteeringBehaviors::Hide(IMovingObject* hunter)
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::Hide(IMovingObject* hunter) ");
	}
	
	//The edge of the map	
	double DistToClosest = 10000.0*10000.0;
	double dist;
	Ogre::Vector3 BestHidingSpot;
	Ogre::Vector3 HidingSpot;

	//Start an iterator at the beginning of the list of stationary objects (Obstacles)
	std::vector<IObject*>::iterator currentOb = GameServices::ObjectManager()->GetStationaryList()->begin();
	std::vector<IObject*>::iterator closest;

	//Search the stationary object list for the closest hiding spot
	while(currentOb != GameServices::ObjectManager()->GetStationaryList()->end())
	{
		HidingSpot = GetHidingPosition((*currentOb)->GetPosition(), (*currentOb)->GetBRadius(), hunter->GetPosition());

		dist = Ogre::Math::Sqr((HidingSpot - m_Vehicle->GetPosition()).length());

		if(dist < DistToClosest)
		{
			DistToClosest = dist;
			BestHidingSpot = HidingSpot;
			closest = currentOb;
		}

		++currentOb;
	}

	//if no hiding place was found within the boundary call evade
	if(DistToClosest == 10000*10000)
	{
		return (Evade(hunter));
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::Hide(IMovingObject* hunter) ");
	}

	//If a hiding spot was found, Arrive to that spot
	return Arrive(BestHidingSpot, FAST);
}

/* WallAvoidance()
 * 
 */
Ogre::Vector3 SteeringBehaviors::WallAvoidance()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::WallAvoidance() ");
	}

	//Create the feelers for the autonomous object
	CreateFeelers();
	double DistToThisIP = 0.0;							//Distance to intersection point
	double DistToClosestIP = 10000.0;					//Distance to closest intersection point, start off at world boundaries
	int ClosestWall = -1;								//The index of the closest wall
	unsigned int flr;									//Count variable for feelers
	int wall;											//Count variable for walls
	Ogre::Vector3 SteeringForce = Ogre::Vector3::ZERO;	//The steering force to be returned
	Ogre::Vector3 point = Ogre::Vector3::ZERO; 			//Temp variable
	Ogre::Vector3 ClosestPoint = Ogre::Vector3::ZERO;	//The closest point found
	Ogre::Vector3 OverShoot = Ogre::Vector3::ZERO;		//Used to calculate the steering force

	for(flr = 0; flr<m_Feelers.size(); flr++)
	{
		for(wall = 0; wall<GameServices::ObjectManager()->GetWallList()->size(); wall++)
		{
			if(GameServices::ObjectManager()->LineIntersection(m_Vehicle->GetPosition(), m_Feelers[flr], 
				GameServices::ObjectManager()->GetWallList()->at(wall)->From(), 
				GameServices::ObjectManager()->GetWallList()->at(wall)->To(), 
				DistToThisIP, point))
			{
				//If this is the closest wall so far
				if(DistToThisIP < DistToClosestIP)
				{
					DistToClosestIP = DistToThisIP;
					ClosestWall = wall;
					ClosestPoint = point;
				}
			}
		}

		//If an intersection has been detected for this feeler update 
		//the steeringforce to move vaway from the detected wall
		if(ClosestWall >= 0)
		{
			OverShoot = m_Feelers[flr] - ClosestPoint;
			SteeringForce = GameServices::ObjectManager()->GetWallList()->at(ClosestWall)->Normal() * OverShoot.length();
		}
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::WallAvoidance() ");
	}
	return SteeringForce;
}

/* FollowPath()
 * 
 */
Ogre::Vector3 SteeringBehaviors::FollowPath()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::FollowPath() ");
	}

	if((m_Path->CurrentWayPoint() - m_Vehicle->GetPosition()).length() < m_WaypointSeekDistSq)
	{
		m_Path->SetNextWaypoint();
	}

	if(!m_Path->Finished())
	{
		if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
		{
			Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::FollowPath() ");
		}

		return Seek(m_Path->CurrentWayPoint());
	}
	else
	{
		if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
		{
			Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::FollowPath() ");
		}

		return Arrive(m_Path->CurrentWayPoint(), NORMAL);
	}
}

/* Wander()
 *
 */
Ogre::Vector3 SteeringBehaviors::Wander()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::Wander() ");
	}

	//Seed the random number generator
	//srand((unsigned)time(NULL));

	//Adjust the jitter with the frame rate
	double JitterThisTimeSlice = m_WanderJitter * m_Vehicle->TimeElapsed();

	//Add a random vector to the wander target
	m_WanderTarget += Ogre::Vector3(  (rand()%50 - rand()%50) * JitterThisTimeSlice, 
									  (rand()%50 - rand()%50) * JitterThisTimeSlice, 0);


	//Project the target on the unit circle
	m_WanderTarget.normalise();

	//Increase the length so the vector is projected on the wander circle
	Ogre::Vector3 target = m_WanderTarget * m_WanderRadius;

	//Move the wander circle infront of the agent
	target = target + m_Vehicle->GetHeading() * m_WanderDistance;

	Ogre::Vector3 Target = GameServices::OgreManager()->GetSceneManager()->getSceneNode(m_Vehicle->GetName())->convertLocalToWorldPosition(target);

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::Wander() ");
	}

	return Target - m_Vehicle->GetPosition();
}

/* Seperation()
 * 
 */
Ogre::Vector3 SteeringBehaviors::Seperation()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::Seperation() ");
	}

	Ogre::Vector3 SteeringForce = Ogre::Vector3::ZERO;	//Varable to hold the calculated force
	Ogre::Vector3 ToAgent;								//Variable to hold the distance from the 
														//owning agent to a target agent

	//For each autonomous object stored in ObjectManagers _autonomousObjectList
	for(unsigned int a = 0; a < GameServices::ObjectManager()->GetAutonomousList()->size(); a++)
	{
		//If the autonomous object is not the owning vehicle and is tagged as in view and is not a target
		if(GameServices::ObjectManager()->GetAutonomousList()->at(a) != m_Vehicle && 
			GameServices::ObjectManager()->GetAutonomousList()->at(a)->IsTagged() && 
			GameServices::ObjectManager()->GetAutonomousList()->at(a) != m_TargetAgent1)
		{
			//Calculate the distance from the owning agent to the target vehicle
			ToAgent = m_Vehicle->GetPosition() - GameServices::ObjectManager()->GetAutonomousList()->at(a)->GetPosition();

			//Add a force proportional to the length of ToAgent
			SteeringForce += (ToAgent.normalisedCopy()/ToAgent.length());
		}
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::Seperation() ");
	}
	return SteeringForce;
}

/* Alignment()
 * 
 */
Ogre::Vector3 SteeringBehaviors::Alignment()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::Alignment() ");
	}

	Ogre::Vector3 AverageHeading = Ogre::Vector3::ZERO;	//Temp var to calculate the average heading
	int NeighborCount = 0;								//Keep a count of other autonomous vehicles near owning vehicle

	//For each autonomous object stored in ObjectManagers _autonomousObjectList
	for(unsigned int a = 0; a < GameServices::ObjectManager()->GetAutonomousList()->size(); a++)
	{
		//If the autonomous object is not the owning vehicle and is tagged as in view and is not a target
		if(GameServices::ObjectManager()->GetAutonomousList()->at(a) != m_Vehicle &&
			GameServices::ObjectManager()->GetAutonomousList()->at(a)->IsTagged() &&
			GameServices::ObjectManager()->GetAutonomousList()->at(a) != m_TargetAgent1)
		{
			//Add this objects heading to the average heading
			AverageHeading += GameServices::ObjectManager()->GetAutonomousList()->at(a)->GetHeading();

			//Increment the neighbor count
			++NeighborCount;
		}
	}

	//If there are any vehicles within view of the owning agent
	if(NeighborCount > 0)
	{
		//Average the average heading
		AverageHeading /= (double)NeighborCount;

		//subtract the owning agents heading
		AverageHeading -= m_Vehicle->GetHeading();
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::Alignment() ");
	}
	return AverageHeading;
}

/* Cohesion()
 * 
 */
Ogre::Vector3 SteeringBehaviors::Cohesion()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::Cohesion() ");
	}

	Ogre::Vector3 CenterOfMass = Ogre::Vector3::ZERO;	//Temp var used to calculate the center of mass
	Ogre::Vector3 SteeringForce = Ogre::Vector3::ZERO;	//Var to calcualate the steering force
	int NeighborCount = 0;								//Keep a count of other autonomous vehicles near owning vehicle

	//For each autonomous object stored in ObjectManagers _autonomousObjectList
	for(unsigned int a = 0; a < GameServices::ObjectManager()->GetAutonomousList()->size(); a++)
	{
		//If the autonomous object is not the owning vehicle and is tagged as in view and is not a target
		if(GameServices::ObjectManager()->GetAutonomousList()->at(a) != m_Vehicle &&
			GameServices::ObjectManager()->GetAutonomousList()->at(a)->IsTagged() &&
			GameServices::ObjectManager()->GetAutonomousList()->at(a) != m_TargetAgent1)
		{
			//Add the objects position to the COM total
			CenterOfMass += GameServices::ObjectManager()->GetAutonomousList()->at(a)->GetPosition();

			//Increment the Neighbor count
			++NeighborCount;
		}

		//If there are any vehicles within view of the owning agent
		if(NeighborCount > 0)
		{
			//Average the COM total
			CenterOfMass /= (double)NeighborCount;

			//Seek the calculated COM
			SteeringForce = Seek(CenterOfMass);
		}
	}

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::Cohesion() ");
	}

	//Return the normalized steering force
	return SteeringForce.normalisedCopy();
}

/* END BEHAVIOR IMPLEMENTATIONS */


/* CalculateWeightedSum()
 *
 */
Ogre::Vector3 SteeringBehaviors::CalculateWeightedSum()
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::CalculateWeightedSum() ");
	}


	if(On(seek))
	{
		if(m_TargetAgent1)
		{
			m_SteeringForce += Seek(m_TargetAgent1->GetPosition()) * m_WeightSeek;
		}
	}

	if(On(pursuit))
	{
		if(m_TargetAgent1)
		{
			m_SteeringForce += Pursuit(m_TargetAgent1) * m_WeightPursuit;
		}
	}

	if(On(arrive))
	{
		if(m_TargetAgent1)
		{
			m_SteeringForce += Arrive(m_TargetAgent1->GetPosition(), m_Deceleration) * m_WeightArrive;
		}
	}

	if(On(interpose))
	{
		if(m_TargetAgent1 != NULL && m_TargetAgent2 != NULL)
		{
			m_SteeringForce += Interpose(m_TargetAgent1, m_TargetAgent2) * m_WeightInterpose;
		}
	}

	if(On(offset_pursuit))
	{
		if(m_TargetAgent1)
		{
			m_SteeringForce += OffsetPursuit(m_TargetAgent1, m_Offset) * m_WeightOffsetPursuit;
		}
	}

	if(On(flee))
	{
		if(m_TargetAgent1)
		{
			m_SteeringForce += Flee(m_TargetAgent1->GetPosition()) * m_WeightFlee;
		}
	}

	if(On(evade))
	{
		if(m_TargetAgent1)
		{
			m_SteeringForce += Evade(m_TargetAgent1) * m_WeightEvade;
		}
	}

	if(On(hide))
	{
		if(m_TargetAgent1)
		{
			m_SteeringForce += Hide(m_TargetAgent1) * m_WeightHide;
		}
	}

	if(On(wall_avoid))
	{
		m_SteeringForce += WallAvoidance() * m_WeightWallAvoid;
	}

	if(On(path_following))
	{
		m_SteeringForce += FollowPath() * m_WeightPathFollowing;
	}

	if(On(wander))
	{
		m_SteeringForce += Wander() * m_WeightWander;
	}

	if(!isSpacePartitioningOn())
	{
		if(On(seperation))
		{
			m_SteeringForce += Seperation() * m_WeightSeperation;
		}

		if(On(alignment))
		{
			m_SteeringForce += Alignment() * m_WeightAlignment;
		}

		if(On(cohesion))
		{
			m_SteeringForce += Cohesion() * m_WeightCohesion;
		}
	}
	else
	{
		if(On(seperation))
		{
		}

		if(On(alignment))
		{
		}

		if(On(cohesion))
		{
		}
	}

	//Truncate to steering force in the x and y directions
	if(m_SteeringForce.x > m_Vehicle->GetMaxForce())
	{
		m_SteeringForce.x = m_Vehicle->GetMaxForce();
	}
	else if(m_SteeringForce.x < -m_Vehicle->GetMaxForce())
	{
		m_SteeringForce.x = -m_Vehicle->GetMaxForce();
	}

	if(m_SteeringForce.y > m_Vehicle->GetMaxForce())
	{
		m_SteeringForce.y = m_Vehicle->GetMaxForce();
	}
	else if(m_SteeringForce.y < -m_Vehicle->GetMaxForce())
	{
		m_SteeringForce.y = -m_Vehicle->GetMaxForce();
	}
	

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::CalculateWeightedSum() ");
	}

	return m_SteeringForce;
}

/* CalculatePrioritized()
 *
 */
Ogre::Vector3 SteeringBehaviors::CalculatePrioritized()
{
	//if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
	//	GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	//{
	//	Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::CalculatePrioritized() ");
	//}

	//Ogre::Vector3 force;

	//if(On(wall_avoid))
	//{
	//	//TODO
	//}

	//if(On(seek))
	//{
	//	force = Seek(GameServices::ObjectManager()->GetPlayerObject(0)->GetPosition()) * m_WeightSeek;

	//	if(!AccumulateForce(m_SteeringForce, force))
	//	{
	//		return m_SteeringForce;
	//	}
	//}

	//if(On(pursuit))
	//{
	//	if(m_TargetAgent1)
	//	{
	//		force = Pursuit(m_TargetAgent1) * m_WeightPursuit;

	//		if(!AccumulateForce(m_SteeringForce, force))
	//		{
	//			return m_SteeringForce;
	//		}
	//	}
	//}

	//if(On(arrive))
	//{
	//	force = Arrive(GameServices::ObjectManager()->GetPlayerObject(0)->GetPosition(), m_Deceleration) * m_WeightArrive;
	//
	//	if(!AccumulateForce(m_SteeringForce, force))
	//	{
	//		return m_SteeringForce;
	//	}
	//}

	//if(On(interpose))
	//{
	//	if(m_TargetAgent1 != NULL && m_TargetAgent2 != NULL)
	//	{
	//		m_SteeringForce += Interpose(m_TargetAgent1, m_TargetAgent2) * m_WeightInterpose;
	//	}
	//}

	//if(On(offset_pursuit))
	//{
	//	if(m_TargetAgent1 && !m_Offset.isZeroLength())
	//	{
	//		force = OffsetPursuit(m_TargetAgent1, m_Offset) * m_WeightOffsetPursuit;

	//		if(!AccumulateForce(m_SteeringForce, force))
	//		{
	//			return m_SteeringForce;
	//		}
	//	}
	//}

	//if(On(flee))
	//{
	//	if(m_TargetAgent1)
	//	{
	//		force = Flee(m_TargetAgent1->GetPosition()) * m_WeightFlee;

	//		if(!AccumulateForce(m_SteeringForce, force))
	//		{
	//			return m_SteeringForce;
	//		}
	//	}
	//}

	//if(On(evade))
	//{
	//	if(m_TargetAgent1)
	//	{
	//		force = Evade(m_TargetAgent1) * m_WeightEvade;

	//		if(!AccumulateForce(m_SteeringForce, force))
	//		{
	//			return m_SteeringForce;
	//		}
	//	}
	//}

	//if(On(hide))
	//{
	//	//TODO
	//}

	//if(On(wall_avoid))
	//{
	//	//TODO
	//}

	//if(On(path_following))
	//{
	//	force = FollowPath() * m_WeightPathFollowing;

	//	if(!AccumulateForce(m_SteeringForce, force))
	//	{
	//		return m_SteeringForce;
	//	}
	//}

	//if(On(wander))
	//{
	//	force = Wander() * m_WeightWander;

	//	if(!AccumulateForce(m_SteeringForce, force))
	//	{
	//		return m_SteeringForce;
	//	}
	//}

	//if(!isSpacePartitioningOn())
	//{
	//	if(On(seperation))
	//	{
	//	}

	//	if(On(alignment))
	//	{
	//	}

	//	if(On(cohesion))
	//	{
	//	}
	//}
	//else
	//{
	//	if(On(seperation))
	//	{
	//	}

	//	if(On(alignment))
	//	{
	//	}

	//	if(On(cohesion))
	//	{
	//	}
	//}

	//Truncate to steering force in the x and y directions
	//if(m_SteeringForce.x > m_Vehicle->GetMaxForce())
	//{
	//	m_SteeringForce.x = m_Vehicle->GetMaxForce();
	//}
	//else if(m_SteeringForce.x < -m_Vehicle->GetMaxForce())
	//{
	//	m_SteeringForce.x = -m_Vehicle->GetMaxForce();
	//}

	//if(m_SteeringForce.y > m_Vehicle->GetMaxForce())
	//{
	//	m_SteeringForce.y = m_Vehicle->GetMaxForce();
	//}
	//else if(m_SteeringForce.y < -m_Vehicle->GetMaxForce())
	//{
	//	m_SteeringForce.y = -m_Vehicle->GetMaxForce();
	//}

	//if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
	//	GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	//{
	//	Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::CalculatePrioritized() ");
	//}
	return m_SteeringForce;
}

/* CalculateDithered()
 *
 */
Ogre::Vector3 SteeringBehaviors::CalculateDithered()
{
	//if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
	//	GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	//{
	//	Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::CalculateDithered() ");
	//}


	//if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
	//	GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	//{
	//	Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::CalculateDithered() ");
	//}
	return Ogre::Vector3::ZERO;
}

/* GetHidingPosition(Ogre::Vector3 posOb, double radiusOb, Ogre::Vector3 posHunter)
 *
 */
Ogre::Vector3 SteeringBehaviors::GetHidingPosition(Ogre::Vector3 posOb, double radiusOb, Ogre::Vector3 posHunter)
{
	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ ENTER SteeringBehaviors::GetHidingPosition(Ogre::Vector3 posOb, double radiusOb, Ogre::Vector3 posHunter) ");
	}

	//Keep a buffer zone between the owning agent and objects in the world
	const double DistanceFromBoundry = 30.0;
	double DistAway = radiusOb + DistanceFromBoundry;

	Ogre::Vector3 ToObj = posOb - posHunter;
	ToObj.normalise();

	if(GameServices::GameEngine()->GetLoggingLevel() >= 4 && 
		GameServices::OgreManager()->GetRoot()->getNextFrameNumber() % 120 == 0)	//debug
	{
		Ogre::LogManager::getSingleton().getLog("Dlog.txt")->logMessage("++++++++++ EXIT SteeringBehaviors::GetHidingPosition(Ogre::Vector3 posOb, double radiusOb, Ogre::Vector3 posHunter) ");
	}

	return (ToObj * DistAway) + posOb;
}